package ${packagePath}.validator;

import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;
import ${packagePath}.entity.${className};

/**
 * ${className}Validator.
 */
public class ${className}Validator extends Validator {
	
	protected void validate(Controller controller) {
		validateRepeat(controller, "repeat", R.Msg.REPEAT_DATE);
	}
	
	protected void handleError(Controller controller) {
		controller.keepModel(${className}.class);
		HashMap<String, Object> map = new HashMap<String, Object>(2);
		map.put("isSuccess", false);
		map.put("msg", R.Msg.REPEAT_DATE);
		controller.renderJson(map);
	}
	
	private void validateRepeat(Controller controller, String errorKey, String errorMessage){
		boolean isRepeat = ConditionDb.isRepeat(${className}.class, "id", controller.getPara("${tableName}.id"));
		if (isRepeat)
			addError(errorKey, errorMessage);
	}
	
}